package repositories

import (
	"context"

	"gorm.io/gorm"

	"github.com/samaa/photosalesplus/backend/internal/models"
)

type MediaAssetRepository interface {
	Create(ctx context.Context, asset *models.MediaAsset) error
	GetByID(ctx context.Context, id uint) (*models.MediaAsset, error)
}

type mediaAssetRepository struct {
	db *gorm.DB
}

func NewMediaAssetRepository(db *gorm.DB) MediaAssetRepository {
	return &mediaAssetRepository{db: db}
}

func (r *mediaAssetRepository) Create(ctx context.Context, asset *models.MediaAsset) error {
	return r.db.WithContext(ctx).Create(asset).Error
}

func (r *mediaAssetRepository) GetByID(ctx context.Context, id uint) (*models.MediaAsset, error) {
	var asset models.MediaAsset
	if err := r.db.WithContext(ctx).First(&asset, id).Error; err != nil {
		return nil, err
	}
	return &asset, nil
}
